package com.example.recyclerviewproject;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity3 extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview_layout3);
        //初始化RecyclerView
        RecyclerView mRecyclerView = findViewById(R.id.mRecyclerView);
        //布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //方向
        layoutManager.setOrientation(RecyclerView.VERTICAL);
        //指定RecyclerView的布局管理--决定RecyclerView的显示方式
   // 网格布局
      //  GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
//瀑布流布局
        //StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, RecyclerView.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        //准备数据
        List<ItemBean> list = new ArrayList<>();
        for (int i = 1; i <=50 ; i++) {
            ItemBean itemBean = new ItemBean();
            itemBean.setTitle("标题==="+i);
            itemBean.setContent("内容+++"+i);
            itemBean.setImageInt(R.mipmap.new_icon);
            list.add(itemBean);
        }
        //创建适配器
        MyAdapter3 myAdapter3 = new MyAdapter3(list, this);
        //给RecyclerView设置适配器
        mRecyclerView.setAdapter(myAdapter3);
        //添加ItemDecoration  - 这里以添加间隔线为例
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, RecyclerView.VERTICAL);
        //添加间隔线
        mRecyclerView.addItemDecoration(dividerItemDecoration);


    }
}
